Fix wrong module end addresses on macOS (LLDB adapter) (#554)#1112
Open
xusheng6 wants to merge 1 commit into
Open
Fix wrong module end addresses on macOS (LLDB adapter) (#554)#1112xusheng6 wants to merge 1 commit into
xusheng6 wants to merge 1 commit into
Conversation
The LLDB adapter computed a module's size as `max(section end) - base` over every section. On macOS this is broken: dyld groups the segments of different modules by type into the shared cache (all __TEXT together, all __DATA together, and a single ~600 MB __LINKEDIT shared by the whole cache), so a module's own segments are scattered across gigabytes and many modules point at the same __LINKEDIT. The max-end therefore spanned most of the shared cache, making every module report a ~2.3 GB size and an end address of -1 in the Modules panel. Compute the extent from the header instead, keeping it to the range the module actually owns via two signals: clip at the next module's load base, and stop extending at the first large gap between the module's own segments. On Linux and for the main executable on macOS (contiguous segments) this yields the true full extent; for shared-cache dylibs it yields the contiguous __TEXT range, matching `image list`/`vmmap`. Verified against /usr/bin/ls with the shared cache mapped: the largest computed module size drops from ~2.3 GB to ~700 KB and no module spans the cache. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #554 — the
Debugger Modulespanel showed an end address of -1 (and a ~2.3 GB size) for every module on macOS.Root cause
LldbAdapter::GetModuleList()computed a module's size asmax(section end) - baseover all of the module's sections. On macOS this is fundamentally broken because dyld does not map system libraries as independent images — it groups the segments of different modules by type into the shared cache:__TEXTsegments are laid out together, all__DATAtogether, etc.;__LINKEDIT(~600 MB) is shared by every module in the cache.So a module's own segments are scattered across gigabytes, and dozens of modules point at the same
__LINKEDIT. Taking the max section end therefore spanned most of the shared cache, producing an absurd size that rendered as end = -1 in the UI.Verified against
/usr/bin/lswith the shared cache mapped — every module reported~0x9xxxxxxx(~2.3 GB); one module even chained through to0x22b1d0000.Fix
Compute the extent from the header segment, keeping it to the range the module actually owns via two signals:
[base, nextModuleBase), so segments that map into a foreign shared-cache region above the next module are dropped.On Linux and for the main executable on macOS (contiguous segments), this yields the true full extent; for shared-cache dylibs it yields the contiguous
__TEXTrange, which is whatimage list/vmmapreport as the module's range.Verification
Simulated the exact algorithm against
/usr/bin/ls(48 modules, shared cache mapped):Notes
This is the targeted bug fix. The proper long-term representation — per-segment ranges and rwx permissions from the real memory map — is tracked under #96; once that lands, this heuristic can be replaced. A comment in the code explains why the end is the owned range and not a naive max-over-sections, to prevent a regression re-adding it.
🤖 Generated with Claude Code